/*
 *  Copyright 2008 Mark Ashworth <javameme@gmail.com>.
 * 
 *  Licensed under the GNU General Public License v3 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.gnu.org/licenses/gpl-3.0.html
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package xperiment.metaphor.persistence.hibernate;

import xperiment.metaphor.model.AbstractSpringJUnit;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.dom4j.Document;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import xperiment.metaphor.model.xml.NamedObjectReferenceResolver;
import xperiment.metaphor.model.xml.ReferenceResolvers;

/**
 *
 * @author Mark Ashworth <javameme@gmail.com>
 */
public class HibernateDaoTest extends AbstractSpringJUnit {
    
    private Map<String, Class> nameMap = new HashMap<String, Class>();
    private ReferenceResolvers resolvers = new ReferenceResolvers();
    
    public HibernateDaoTest(String testName) {
        super(testName);
        
//        nameMap.put("gender", Gender.class);
//        nameMap.put("population_group", PopulationGroup.class);
//        nameMap.put("person", Person.class);
//        nameMap.put("employee", Employee.class);
//        nameMap.put("user_login", User.class);
//        nameMap.put("role", Role.class);
        
        
        resolvers.addResolver(new NamedObjectReferenceResolver());
    }            
    
    public void testImportDataSet() throws Exception {
        logger.info("importDataSet");
        
        URL url = HibernateDaoTest.class.getResource("/sample_data_class.xml");
        assertNotNull(url);
        
        DocumentFactory factory = DocumentFactory.getInstance();
        SAXReader reader = new SAXReader(factory);
        Document doc = reader.read(url);
        Element root = doc.getRootElement();
        List<Element> elements = root.elements();
        for (Element element : elements) {
            resolvers.resolve(element);
        }
    }
}
